home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************
- / getbar()
- /
- / This routine displays a list of options in a line-by-line format
- / and allows the user to select one of the options by pressing the
- / space key (and some others optionally). This routine has the
- / same appearance of the Zenith SETUP command in ROM, and some other
- / software too. The options are:
- /
- / HOME key: move to top selection
- /
- / END key: move to last selection
- /
- / BACKSPACE key
- / UP cursor
- / BACKTAB keys: move to selection above (circular)
- /
- / SPACE
- / DOWN cursor
- / TAB keys: move to selection below (circular)
- /
- / ENTER key: accept current selection highlighted
- /
- / other keys: beeps, and waits
- /
- / INPUT from caller:
- / The current cursor location will be used. When the routine
- / returns, the cursor will be in the same column, but under
- / the last prompt. This routine needs to be passed a
- / pointer to an array of strings, and an indication of which
- / is the default. The last+1 element must be *NULL, and no
- / maxcount need be supplied.
- /
- / OUTPUT:
- / besides screen display, etc., routine returns 0-based response
- / to selection (the array element selected)
- /
- / GLOBAL VARIABLES ALTERED:
- / none
- ***********************************************************************/
-
- #include <stdio.h>
- #include <hamdefs.h>
- #include <stdlib.h>
-
- #define SPECIAL (NORMAL|HILITE)
-
- int getbar(choices, deflt)
- char *choices[];
- int deflt;
- {
- int i, count, r, c, keystroke, longest, length;
- int *attrib;
-
- for (longest = count = 0; choices[count] != NULL; ++count) {
- if ((length = strlen(choices[count])) > longest)
- longest = length;
- }
-
- findcsr(&r, &c);
-
- attrib = (int *)calloc(count, sizeof(int));
-
- for (i = 0; i < count; i++)
- attrib[i] = NORMAL;
-
- attrib[deflt] = SPECIAL;
-
- clrblk(r - 1, c - 1, r + count, c + longest);
-
- for (i = 0; i < count; i++)
- atputsa(r + i, c, choices[i], attrib[i]);
-
- scrbox(r - 1, c - 1, r + count, c + longest, 1, NORMAL);
-
- locate(r + count, c);
- while ((keystroke = inkeyi()) != CR) {
- switch (keystroke) {
- case HOME:
- attrib[deflt] = NORMAL;
- atputsa(r + deflt, c, choices[deflt], attrib[deflt]);
- deflt = 0;
- attrib[deflt] = SPECIAL;
- atputsa(r + deflt, c, choices[deflt], attrib[deflt]);
- break;
- case END:
- attrib[deflt] = NORMAL;
- atputsa(r + deflt, c, choices[deflt], attrib[deflt]);
- deflt = count - 1;
- attrib[deflt] = SPECIAL;
- atputsa(r + deflt, c, choices[deflt], attrib[deflt]);
- break;
- case BS:
- case UP:
- case BACKTAB:
- attrib[deflt] = NORMAL;
- atputsa(r + deflt, c, choices[deflt], attrib[deflt]);
- if (deflt == 0)
- deflt = count - 1;
- else
- --deflt;
- attrib[deflt] = SPECIAL;
- atputsa(r + deflt, c, choices[deflt], attrib[deflt]);
- break;
- case ' ':
- case DOWN:
- case '\t':
- attrib[deflt] = NORMAL;
- atputsa(r + deflt, c, choices[deflt], attrib[deflt]);
- if (deflt == (count - 1))
- deflt = 0;
- else
- ++deflt;
- attrib[deflt] = SPECIAL;
- atputsa(r + deflt, c, choices[deflt], attrib[deflt]);
- break;
-
- default:
- beep();
- break;
- }
- locate(r + count, c);
- }
- free(attrib);
- return deflt;
- }
-
-